<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Getting Started  Reference</title>
    <link rel="stylesheet" type="text/css" href="css/jazzy.css" />
    <link rel="stylesheet" type="text/css" href="css/highlight.css" />
    <meta charset='utf-8'>
    <script src="js/jquery.min.js" defer></script>
    <script src="js/jazzy.js" defer></script>
    
  </head>
  <body>
    <a title="Getting Started  Reference"></a>
    <header>
      <div class="content-wrapper">
        <p><a href="index.html">Pisth_API Docs</a> (100% documented)</p>
        <p class="header-right"><a href="https://github.com/ColdGrub1384/Pisth"><img src="img/gh.png"/>View on GitHub</a></p>
        <p class="header-right"><a href="dash-feed://https%3A%2F%2Fpisth%2Egithub%2Eio%2Fdocs%2Fapi%2Fdocsets%2FPisth%2Exml"><img src="img/dash.png"/>Install in Dash</a></p>
      </div>
    </header>
    <div class="content-wrapper">
      <p id="breadcrumbs">
        <a href="index.html">Pisth_API Reference</a>
        <img id="carat" src="img/carat.png" />
        Getting Started  Reference
      </p>
    </div>
    <div class="content-wrapper">
      <nav class="sidebar">
        <ul class="nav-groups">
          <li class="nav-group-name">
            <a href="Guides.html">Guides</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="getting-started.html">Getting Started</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="Classes.html">Classes</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="Classes/Pisth.html">Pisth</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/PisthAPT.html">PisthAPT</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/PisthFile.html">PisthFile</a>
              </li>
            </ul>
          </li>
        </ul>
      </nav>
      <article class="main-content">
        <section>
          <section class="section">
            
            <h1 id='getting-started' class='heading'>Getting started</h1>

<ul>
<li>Declare an URL scheme for your app, preferably just for importing files. Use an unique URL scheme, it&rsquo;s very important! Don&rsquo;t use URL schemes like <q>pisth-import</q>, try to include the name of your app, for example: <q>myApp-pisth-import</q>.</li>
<li>Include the Pisth_API framework and Pisth_Shared: Drag the <code>Pisth API</code> and <code>Pisth Shared</code> projects to your workspace and add them to your app&rsquo;s embedded binary.</li>
<li>Add this to your <code>info.plist</code>:</li>
</ul>
<pre class="highlight xml"><code> <span class="nt">&lt;key&gt;</span>LSApplicationQueriesSchemes<span class="nt">&lt;/key&gt;</span>
 <span class="nt">&lt;array&gt;</span>
 <span class="nt">&lt;string&gt;</span>pisthapt<span class="nt">&lt;/string&gt;</span>
 <span class="nt">&lt;string&gt;</span>pisth-import<span class="nt">&lt;/string&gt;</span>
 <span class="nt">&lt;/array&gt;</span>
</code></pre>
<h2 id='opening-pisth-apt-connection' class='heading'>Opening Pisth APT connection</h2>

<ul>
<li>Configure the <code><a href="Classes/PisthAPT.html">PisthAPT</a></code> instance:</li>
</ul>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">pisthAPT</span> <span class="o">=</span> <span class="kt">PisthAPT</span><span class="p">(</span><span class="nv">urlScheme</span><span class="p">:</span> <span class="kt">URL</span><span class="p">(</span><span class="nv">string</span><span class="p">:</span> <span class="s">"pisth-api://"</span><span class="p">)</span><span class="o">!</span> <span class="cm">/* This app's URL Scheme */</span><span class="p">)</span>
</code></pre>

<ul>
<li>Setup the connection:</li>
</ul>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">connection</span> <span class="o">=</span> <span class="kt">RemoteConnection</span><span class="p">(</span><span class="nv">host</span><span class="p">:</span> <span class="s">"coldg.ddns.net"</span><span class="p">,</span> <span class="nv">username</span><span class="p">:</span> <span class="s">"pisthtest"</span><span class="p">,</span> <span class="nv">password</span><span class="p">:</span> <span class="s">"pisth"</span><span class="p">,</span> <span class="nv">name</span><span class="p">:</span> <span class="s">"Pisth Test"</span><span class="p">,</span> <span class="nv">path</span><span class="p">:</span> <span class="s">"~"</span><span class="p">,</span> <span class="nv">port</span><span class="p">:</span> <span class="mi">22</span><span class="p">,</span> <span class="nv">useSFTP</span><span class="p">:</span> <span class="kc">false</span><span class="p">,</span> <span class="nv">os</span><span class="p">:</span> <span class="s">"Raspbian"</span><span class="p">)</span>
</code></pre>

<ul>
<li>Now, open the connection calling <code>pisthAPT.open(connection: connection)</code> and check if Pisth APT is installed with <code>pisthAPT.canOpen</code>.</li>
</ul>
<h2 id='importing-files-from-pisth' class='heading'>Importing files from Pisth</h2>

<ul>
<li>Configure the <code><a href="Classes/Pisth.html">Pisth</a></code> instance:</li>
</ul>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">pisth</span> <span class="o">=</span> <span class="kt">Pisth</span><span class="p">(</span><span class="nv">message</span><span class="p">:</span> <span class="kc">nil</span> <span class="cm">/* Default message */</span><span class="p">,</span> <span class="nv">urlScheme</span><span class="p">:</span> <span class="kt">URL</span><span class="p">(</span><span class="nv">string</span><span class="p">:</span> <span class="s">"pisth-api://"</span><span class="p">)</span><span class="o">!</span> <span class="cm">/* This app URL scheme */</span><span class="p">)</span>
</code></pre>

<ul>
<li>Handle data received in your App delegate:</li>
</ul>
<pre class="highlight swift"><code><span class="kd">import</span> <span class="kt">Pisth_API</span>

<span class="kd">@UIApplicationMain</span>
<span class="kd">class</span> <span class="kt">AppDelegate</span><span class="p">:</span> <span class="kt">UIResponder</span><span class="p">,</span> <span class="kt">UIApplicationDelegate</span> <span class="p">{</span>

    <span class="kd">func</span> <span class="nf">application</span><span class="p">(</span><span class="n">_</span> <span class="nv">app</span><span class="p">:</span> <span class="kt">UIApplication</span><span class="p">,</span> <span class="kd">open</span> <span class="nv">url</span><span class="p">:</span> <span class="kt">URL</span><span class="p">,</span> <span class="nv">options</span><span class="p">:</span> <span class="p">[</span><span class="kt">UIApplicationOpenURLOptionsKey</span> <span class="p">:</span> <span class="kt">Any</span><span class="p">]</span> <span class="o">=</span> <span class="p">[:])</span> <span class="o">-&gt;</span> <span class="kt">Bool</span> <span class="p">{</span>

        <span class="c1">// Getting data received</span>
        <span class="n">pisth</span><span class="o">.</span><span class="n">receivedFile</span><span class="p">?</span><span class="o">.</span><span class="n">data</span>

        <span class="c1">// Getting received file name</span>
        <span class="n">pisth</span><span class="o">.</span><span class="n">receivedFile</span><span class="p">?</span><span class="o">.</span><span class="n">filename</span>

    <span class="p">}</span>
<span class="p">}</span>
</code></pre>

<ul>
<li>Now, start importing file calling <code>pisth.importFile()</code>. Check if Pisth is installed with <code>pisth.canOpen</code>.</li>
</ul>

          </section>
        </section>
        <section id="footer">
          <p>&copy; 2018 <a class="link" href="" target="_blank" rel="external"></a>. All rights reserved. (Last updated: 2018-07-13)</p>
          <p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.9.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
        </section>
      </article>
    </div>
  </body>
</div>
</html>
